# 3.24 Button Control Fan ## 3.24.1 Overview In this experiment, we program to control the fan by a button. ## 3.24.2 Code Flow ![t166](./media/t166.png) ## 3.24.3 Test Code You can manually build blocks, or directly open the code file we provide: `3-24-Button Control Fan.ubp`. If you have any questions about how to open code files or upload code, please back to `1.9 Upload Code`. **Build code blocks:** 1. In ![](./media/control.png), drag ![](./media/t1.png) and ![](./media/t2.png) to the script area, and stack them together. ![t34](./media/t34.png) 2. Press the red button to turn off the fan and delay for 300ms, otherwise press the green button to turn on the fan and delay for 300ms ![t167](./media/t167.png) ## 3.24.4 Test Result Connect the coding box to the MicroBlocks via USB or Bluetooth, and click ![t59](./media/t59.png) to upload the code to the coding box. When we press the green button, the fan will turn on. When we press the red button, the fan stops working.